package com.bit.book.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;
@Slf4j
@Aspect
@Configuration
public class TimeRecordAspect {
    @Around("execution (* com.bit.book.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        /*1、记录开始时间
        2、执行目标方法
        3、记录结束时间
        4、打印耗时+返回目标方法
        * */
        Long start = System.currentTimeMillis();
        //执行目标方法
        Object proceed = joinPoint.proceed();
        Long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature() + "耗时{}", end - start);
        return proceed;
    }

}
